package com.ruoyi.web.controller.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SetModel;
import com.ruoyi.system.domain.base.MesOperations;
import com.ruoyi.system.service.IMesOperationsService;
import com.ruoyi.system.service.ISetModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序Controller
 *
 * @author ruoyi
 * @date 2023-02-20
 */
@Api(tags = "工艺工步api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/operations" )
public class MesOperationsController extends BaseController {

    private final IMesOperationsService iMesOperationsService;

    private final ISetModelService setModelService;

    /**
     * 查询工序列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MesOperations mesOperations)
    {
        startPage();
        LambdaQueryWrapper<MesOperations> lqw = new LambdaQueryWrapper<MesOperations>();
        if (StringUtils.isNotBlank(mesOperations.getProductCode())){
            lqw.eq(MesOperations::getProductCode ,mesOperations.getProductCode());
        }
        if (StringUtils.isNotBlank(mesOperations.getOperationCode())){
            lqw.like(MesOperations::getOperationCode ,mesOperations.getOperationCode());
        }
        if (StringUtils.isNotBlank(mesOperations.getOperationName())){
            lqw.like(MesOperations::getOperationName ,mesOperations.getOperationName());
        }
        if (mesOperations.getOperationNum() != null){
            lqw.eq(MesOperations::getOperationNum ,mesOperations.getOperationNum());
        }
        if (StringUtils.isNotBlank(mesOperations.getWorkShopCode())){
            lqw.like(MesOperations::getWorkShopCode ,mesOperations.getWorkShopCode());
        }
        if (StringUtils.isNotBlank(mesOperations.getLineCode())){
            lqw.like(MesOperations::getLineCode ,mesOperations.getLineCode());
        }
        if (StringUtils.isNotBlank(mesOperations.getStationCode())){
            lqw.like(MesOperations::getStationCode ,mesOperations.getStationCode());
        }
        if (StringUtils.isNotBlank(mesOperations.getTechnicalRequire())){
            lqw.eq(MesOperations::getTechnicalRequire ,mesOperations.getTechnicalRequire());
        }
        if (mesOperations.getBeatTime() != null){
            lqw.eq(MesOperations::getBeatTime ,mesOperations.getBeatTime());
        }
        if (StringUtils.isNotBlank(mesOperations.getDoWorkPicture())){
            lqw.eq(MesOperations::getDoWorkPicture ,mesOperations.getDoWorkPicture());
        }
        if (StringUtils.isNotBlank(mesOperations.getOperationCard())){
            lqw.eq(MesOperations::getOperationCard ,mesOperations.getOperationCard());
        }
        List<MesOperations> list = iMesOperationsService.list(lqw);

        return getDataTable(list);
    }


    @ApiOperation(value = "查询工艺工步列表所有")
    @GetMapping("/getList")
    public List<MesOperations> getList()
    {
        List<MesOperations> list = iMesOperationsService.getList();
        return list;
    }

    /**
     * 导出工序列表
     */
    @Log(title = "工序" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MesOperations mesOperations) {
        LambdaQueryWrapper<MesOperations> lqw = new LambdaQueryWrapper<MesOperations>(mesOperations);
        List<MesOperations> list = iMesOperationsService.list(lqw);
        ExcelUtil<MesOperations> util = new ExcelUtil<MesOperations>(MesOperations. class);
        return util.exportExcel(list, "operations" );
    }

    /**
     * 获取工序详细信息
     */
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMesOperationsService.getById(id));
    }

    /**
     * 获取工艺路线编码
     */
    @ApiOperation(value = "获取工艺路线编码")
    @GetMapping("/getRoutingCodeList")
    public AjaxResult getRoutingCodeList() {
        return AjaxResult.success(iMesOperationsService.getRoutingCodeList());
    }

    /**
     * 新增工序
     */
    @Log(title = "工序" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesOperations mesOperations) {
        return toAjax(iMesOperationsService.save(mesOperations) ? 1 : 0);
    }

    /**
     * 修改工序
     */
    @Log(title = "工序" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesOperations mesOperations) {
        return toAjax(iMesOperationsService.updateById(mesOperations) ? 1 : 0);
    }

    /**
     * 删除工序
     */
    @Log(title = "工序" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iMesOperationsService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
